class Solution:
    def numDecodings(self, s: str) -> int:
        # done, 1, 2
        node_stat = [1, 0, 0]
        for c in s:
            new_node_stat = [0, 0, 0]

            if c != '0':
                new_node_stat[0] += node_stat[0]
            new_node_stat[0] += node_stat[1]
            if c in '0123456':
                new_node_stat[0] += node_stat[2]

            if c == '1':
                new_node_stat[1] += node_stat[0]

            if c == '2':
                new_node_stat[2] += node_stat[0]

            node_stat = new_node_stat
        return node_stat[0]


s = '12'
print(Solution().numDecodings(s))

s = "226"
print(Solution().numDecodings(s))

s = "06"
print(Solution().numDecodings(s))

# def brutal_solve(s):
#
#
#
# def test():
#     import random
#     for _ in range(10000):
#         v = random.randint(0, 999)
#         s = str(v)
#         if random.randint(0, 10) == 0:
#             s = '0' + s
